<?php


namespace App\Logic;


use App\Interfaces\Order;
use App\Interfaces\OrderValidator;
use App\Repository\OrderRepository;
use mysql_xdevapi\Exception;

class RecentOrderValidator implements OrderValidator
{

    /**
     * RecentOrderValidator constructor.
     */
    public function __construct(OrderRepository $order)
    {
        $this->order = $order;
    }

    public function validate(Order $order)
    {
        // TODO: Implement validate() method.
        $recent = $this->order->getRecentOrderCount($order->account);
        if ($recent > 0) {
            throw  new Exception("Duplicate order likely");
        }
    }
}